import io
import sys

ALIAS = {
    'l': 'look',
    'e': 'go east',
    's': 'go south',
    'w': 'go west',
    'n': 'go north',
    'u': 'go up',
    'd': 'go down',
    'z': 'go (0,0,0)'
}


async def main(ob, args):
    cmds = [_ for _ in ob.m.system.cmds.__dict__.keys() if _[0:2] != '__']
    msg = 'Commands:\n'
    for i in range(0, len(cmds), 8):
        #msg += '\t'
        msg += '\t'.join(cmds[i:i+8])
        msg += '\n'
    await ob.m.tell_user(ob, msg)
    return True


def safe_parse_args(parser, sys_args):
    args, exit_code, msg = None, None, None

    try:
        std_buffer = io.StringIO()
        original_stdout = sys.stdout
        original_stderr = sys.stderr
        sys.stdout = std_buffer
        sys.stderr = std_buffer
        args = parser.parse_args(sys_args)
    except SystemExit:
        captured_stderr = std_buffer.getvalue()
        msg = f'{captured_stderr}'
        exit_code = SystemExit.code
    finally:
        sys.stdout = original_stdout
        sys.stderr = original_stderr

    return args, exit_code, msg

